const http = require("http");
const fs = require("fs");
const path = require("path");
const argvArr = process.argv;

var fileWrite = argvArr[2];

http.createServer((rep, res) => {
    
    fs.access(__dirname + "/" + fileWrite, err => {
        if(err && fileWrite != null){
            console.log(err);
            return err;
        }
        else{
            if(fileWrite != null){
                var filePath = path.join(__dirname, "/" + fileWrite);
            }
            else{
                var filePath = path.join(__dirname, "/fileReader1.js");
            }
            
            var readable = fs.createReadStream(filePath);
            readable.pipe(res);
        }
    })
}).listen(8081);

console.log("sever is listening 8081");
